package com.simpleim.starter.sender;

import com.simpleim.im.common.bean.msg.ProtoMsg;
import com.simpleim.starter.protoBuilder.LoginMsgBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 登录发送器
 */
@Service
public class LoginSender extends BaseSender{

    private static final Logger LOG = LoggerFactory.getLogger(LoginSender.class);

    public void sendLoginMsg() {
        if (!isConnected()) {
            LOG.info("连接还未建立，无法发送登录");
            return;
        }
        // 如果没有连接
        ProtoMsg.Message message = LoginMsgBuilder.buildLoginMsg(getUser(), getSession());
        super.sendMsg(message);
    }

    @Override
    public void sendSuccess(ProtoMsg.Message message) {
        LOG.info("登录成功");
    }

    @Override
    public void sendFail(ProtoMsg.Message message) {
        LOG.info("登录失败");
    }
}
